<template>
  <div class="all-tag">
    <!-- 三角形 -->
    <div class="triangle"></div>
    <!-- 弹出框 -->
    <div class="alltag">
      <div @click.stop="switchTag(-1)">全部标签</div>
      <div>
        <span
          v-for="(item,index) in tagList"
          :key="item.val"
          :style="{'backgroundColor':item.color}"
          @click.stop="switchTag(index)"
          @click="clicktag(item)"
        >{{item.title}}</span>
        <span class="itemempty"></span>
        <span class="itemempty"></span>
        <span class="itemempty"></span>
        <div v-if="isNoneData" style="text-align:center">{{noneData}}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "alltag",
  data() {
    return {
      noneData: "没有标签",
      isNoneData: false,
      tagList: [],
      switchTagVal: ""
    };
  },
  created() {
    this.getTagList();
  },
  methods: {
    clicktag(data) {
      this.$emit("clicktag", data);
    },
    switchTag(index) {
      if (index == -1) {
        var allTag = "全部标签";
      }
      this.switchTagVal = this.tagList[index];
      this.$emit("switchTag", this.switchTagVal, allTag);
    },
    getTagList() {
      try {
        let res = this.$api.tag
          .taglist({
            access_token: localStorage.getItem("access_token")
          })
          .then(res => {
            if (res.error == 40002) {
              this.$router.push("/register");
            } else if (res.error == 1000) {
              this.isNoneData = true;
              return false;
            } else if (res.error == 0) {
              this.isNoneData = false;
              this.tagList = res.data.items;
            }
            layer.open({
                content: res.msg,
                skin: "msg",
                time: 2
              });
          });
      } catch (e) {}
    }
  }
};
</script>

<style lang="less" scoped>
.all-tag {
  .triangle {
    width: 0;
    height: 0;
    position: fixed;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 1.5rem 3rem;
    border-style: solid;
    border-color: transparent transparent rgb(10, 1, 35);
  }
  .alltag {
    width: 90%;
    height: 70%;
    padding: 1.2rem 1.8rem;
    position: fixed;
    left: 50%;
    top: 7rem;
    transform: translateX(-50%);
    background-color: rgb(10, 1, 35);
    border-radius: 0.5rem;
    overflow-y: auto;
    > div:first-of-type {
      padding: 0.5rem 1.2rem;
      background-color: #fff;
      border-radius: 0.4rem;
      text-align: center;
      margin-bottom: 0.8rem;
    }
    > div:last-of-type {
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      span {
        min-height: 2.4rem;
        max-height: 2.4rem;
        line-height: 2.4rem;
        padding: 0 1.2rem;
        margin-right: 1rem;
        margin-bottom: 0.8rem;
        letter-spacing: 0.05rem;
        color: #fff;
        display: inline-block;
        background-color: pink;
        border-radius: 0.4rem;
      }
      .itemempty {
        height: 0;
        width: 0;
        padding: 0;
      }
    }
  }
}
</style>
